package com.pet.item.controller;


import com.pet.common.domain.Result;
import com.pet.item.domain.po.Store;
import com.pet.item.domain.query.StoreQuery;
import com.pet.item.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商店信息表 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-07-03
 */
@RestController
@Api(tags = "商店信息")
@RequestMapping("/stores")
@RequiredArgsConstructor
public class StoreController {
    private final IStoreService storeService;

    @PostMapping("/list")
    @ApiOperation("分页获取店铺详情信息")
    public Result getStoreList(@RequestBody StoreQuery storeQuery) {
        return Result.success(storeService.getStoreList(storeQuery));
    }

    @GetMapping("/nearby")
    @ApiOperation("获取附近商店信息列表")
    public Result getStoreListForMap() {
        return Result.success(storeService.getStoreListForMap());
    }

    @PostMapping
    @ApiOperation("添加商店信息")
    public Result addStore(@RequestBody Store store) {
        boolean isSucceed = storeService.addStore(store);
        return isSucceed ? Result.success() : Result.error();
    }

    @PutMapping
    @ApiOperation("更新商店信息")
    public Result updateStore(@RequestBody Store store) {
        boolean isSucceed = storeService.updateById(store);
        return isSucceed ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除商店信息")
    public Result deleteStore(@PathVariable @ApiParam(value = "商店id", required = true) Integer id) {
        boolean isSucceed = storeService.removeById(id);
        return isSucceed ? Result.success() : Result.error();
    }

    @GetMapping("/brief/{id}")
    @ApiOperation("根据商店id获取简要商店信息")
    public Result getStoreBriefById(@PathVariable Integer id) {
        return storeService.getStoreBriefById(id);
    }
}
